import request from '@/api/request.js'

/**
 * 免账号密码使用userId登录，大家需要使用自己的登录逻辑
 * @param {String} userId 用户userId
 */
export function login(userId){
	return request({url: `/sys/auth/login/ignore/${userId}`})
}

//查询组织架构列表
export function getOrgTree(params) {
  return request({
    url: '/oa/org/tree',
    data: params
  })
}

//查询用户历史签名
export function getUserSign() {
  return request({url: '/oa/org/user/sign'})
}

// 查询系统角色列表
export function getRole() {
  return request({url: '/oa/org/role'})
}

// 搜索人员
export function getUserByName(params) {
  return request({
    url: '/oa/org/tree/user/search',
    data: params,
  })
}

// 搜索人员
export function getUserDepts(userId) {
  return request({url: `/oa/org/user/${userId}/dept`})
}

// 获取审批代理人
export function getUserAgent() {
  return request({url: `/oa/org/user/agent`})
}

// 获取审批代理人
export function setUserAgent(params) {
  return request({
    url: `/oa/org/user/agent`,
    method: 'PUT',
    data: params,
  })
}

// 取消审批代理人
export function cancelUserAgent() {
  return request({
    url: `/oa/org/user/agent`,
    method: 'DELETE',
  })
}

// 查询用户详细资料
export function getUserDetail(userId) {
  return request({
    url: `/oa/org/user/${userId}/detail`,
    method: 'GET',
  })
}

// 登录 单点登录
export function getUserinfo(code) {
  return request({
    url: `/sys/auth/userinfo/${code}`,
    method: 'GET',
  })
}

// 登录画面接口
// http://10.1.22.31:9991/sys/auth/newLogin?username=E0000594&password=123456
export function loginPage(param) {
  return request({
      url: `sys/auth/newLogin?username=${param.username}&password=${param.password}`,
      method: 'get',
      params: param,
  })
}

export default {
	login, getOrgTree, getUserSign, getRole,
	getUserByName, getUserDepts, getUserAgent,
	setUserAgent, cancelUserAgent, getUserDetail,getUserinfo,loginPage
}
